package com.njtoyo.taxi.admin.rest.controller.marketing;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.aop.SensitiveOperation;
import com.njtoyo.taxi.admin.rest.presenter.marketing.coupon.AdminGiveCustomerCouponLogListPresenter;
import com.njtoyo.taxi.admin.rest.presenter.marketing.coupon.CouponHotListPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.marketing.coupon.AdminGiveLogQueryWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.marketing.coupon.CouponHotQueryWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.marketing.coupon.CreateWrapper;
import com.njtoyo.taxi.admin.service.marketing.CouponService;
import com.taxi.entity.common.RestResult;
import com.njtoyo.taxi.entity.backend.AdminUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

@RestController
@RequestMapping("/marketing/coupon")
@Api(tags = "优惠券管理")
public class CouponController {
    @Autowired
    private CouponService couponService;

    @PostMapping("/customer_give_coupon")
    @ApiOperation(value = "给用户发送优惠券", notes = "权限：customer_give_coupon")
    @PermissionScope(names = {"customer_give_coupon"})
    @ApiOperationSupport(order = 1)
    @SensitiveOperation(name = "give_coupon_to_single_customer")
    public RestResult customerGiveCoupon(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, @Valid @RequestBody CreateWrapper wrapper) {
        return couponService.customerGiveCoupon(adminUser, wrapper);
    }

    @GetMapping("/admin_give_log")
    @ApiOperation(value = "管理员发券日志列表", notes = "权限：admin_give_coupon_log")
    @PermissionScope(names = {"admin_give_coupon_log"})
    @ApiOperationSupport(order = 2)
    public RestResult<PageImpl<AdminGiveCustomerCouponLogListPresenter>> adminGiveLog(AdminGiveLogQueryWrapper wrapper) {
        return couponService.adminGiveLog(wrapper);
    }

    @GetMapping("/customer/{customer_id}/coupon/hot")
    @ApiOperation(value = "指定乘客的活跃优惠券列表", notes = "权限：customer_coupon_hot")
    @PermissionScope(names = {"customer_coupon_hot"})
    @ApiOperationSupport(order = 3)
    public RestResult<Page<CouponHotListPresenter>> couponHot(@PathVariable("customer_id") Long customerId, CouponHotQueryWrapper wrapper) {
        return couponService.couponHot(customerId, wrapper);
    }
}
